home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / starview / examples / output / mapmode.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-31  |  5.9 KB  |  204 lines

  1. /*******************************************************************
  2. *  MAPMODE.CXX
  3. *  (c) 1992 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. // --- class MyApp -------------------------------------------------
  9.  
  10. class MyApp : public Application
  11. {
  12. public:
  13.     virtual void Main( int, char*[] );
  14. };
  15.  
  16. // --- class PaintWindow -------------------------------------------
  17.  
  18. class PaintWindow : public WorkWindow
  19. {
  20. protected:
  21.     AutoTimer       aTimer;
  22.     USHORT          a;
  23.     USHORT          x;
  24.     USHORT          y;
  25.     USHORT          t;
  26.     BOOL            bOpen;
  27.     BOOL            bMapModeChanged;
  28.  
  29. public:
  30.                     PaintWindow();
  31.  
  32.     virtual void    Paint( const Rectangle& );
  33.     virtual void    Resize();
  34.     virtual void    MouseButtonDown(const MouseEvent &);
  35.  
  36.     void            PacMan( AutoTimer* );
  37. };
  38.  
  39. // --- PaintWindow::PaintWindow() ----------------------------------
  40.  
  41. PaintWindow::PaintWindow() :
  42.                  WorkWindow( NULL, WB_APP | WB_STDWORK )
  43. {
  44.     aTimer.ChangeTimeout( 60 );
  45.     aTimer.ChangeTimeoutHdl( LINK( this, PaintWindow::PacMan ) );
  46.     aTimer.Start();
  47.  
  48.     t = 0;
  49.     bOpen = TRUE;
  50.     bMapModeChanged = FALSE;
  51.  
  52.     SetText( "MapMode" );
  53.     Show();
  54. }
  55.  
  56. // --- PaintWindow::Paint() ----------------------------------------
  57.  
  58. void PaintWindow::Paint( const Rectangle& )
  59. {
  60.     Point aPointArray[4];
  61.  
  62.     MapMode aOldMode = ChangeMapMode( MapMode() );
  63.     DrawText( Point( 0, 0 ), "Press a MouseButton" );
  64.     ChangeMapMode( aOldMode );
  65.  
  66.     ChangePen( Pen( Color( COL_BLACK ), 0 ) );
  67.     ChangeFillInBrush( Brush( Color( COL_GREEN ) ) );
  68.     DrawRect( Rectangle( Point( x/8, y/8 ),
  69.                          Size( x/4, y/4 ) ), 10, 10 );
  70.  
  71.     ChangePen( Pen( Color( COL_BLUE ), 3 ) );
  72.     DrawArc( Rectangle( Point( 0, 0 ), Point( x-x/8, y-y/8 ) ),
  73.                         Point( x/2, y ), Point( x, y/2 ) );
  74.  
  75.     ChangePen( Pen( Color( COL_CYAN ), 2 ) );
  76.     aPointArray[0] = Point( x/2, y/2 );
  77.     aPointArray[1] = Point( 3*x/4, y );
  78.     aPointArray[2] = Point( x, 3*y/4 );
  79.     aPointArray[3] = Point( x/3, 4*y/5 );
  80.     DrawPolyLine( 4, aPointArray );
  81.  
  82.     ChangePen( Pen( Color( COL_LIGHTGREEN ), 1, PEN_DASH ) );
  83.     aPointArray[0] = Point( x/2, y/2-y/10 );
  84.     aPointArray[1] = Point( 3*x/4, y-y/10 );
  85.     aPointArray[2] = Point( x, 3*y/4-y/10 );
  86.     aPointArray[3] = Point( x/3, 4*y/5-y/10 );
  87.     DrawPolyLine( 4, aPointArray );
  88.  
  89.     ChangePen( Pen( PEN_NULL ) );
  90.     ChangeFillInBrush( Brush( Color( COL_BLACK ),
  91.                               Color( COL_WHITE ),
  92.                               BRUSH_VERT ) );
  93.     DrawRect( Rectangle( Point( 3*x/4, y/6 ), Size( x/5, y/5 ) ) );
  94.  
  95.     ChangeFillInBrush( Brush( Color( COL_LIGHTMAGENTA ),
  96.                               BRUSH_DIAGCROSS ) );
  97.     DrawEllipse( Rectangle( Point( 3*x/4, y/6 ),
  98.                             Size( x/4, y/4 ) ) );
  99.  
  100.     ChangePen( Pen( Color( COL_BLACK ), 1 ) );
  101.     ChangeFillInBrush( Brush( Color( COL_MAGENTA ) ) );
  102.     aPointArray[0] = Point( x/8, y/2 );
  103.     aPointArray[1] = Point( x/3, 2*y/3 );
  104.     aPointArray[2] = Point( 1, y-1 ) ;
  105.     DrawPolygon( 3, aPointArray );
  106.  
  107.     ChangePen( Pen( Color( COL_BLACK ), 2 ) );
  108.     ChangeFillInBrush( Brush( Color( COL_RED ), BRUSH_CROSS ) );
  109.     DrawEllipse( Rectangle( Point( x/2, y/3),
  110.                             Point( x/2+x/5, y/2 ) ) );
  111.  
  112.     ChangeFillInBrush( Brush( BRUSH_NULL ) );
  113.     DrawEllipse( Rectangle( Point( x/2, y-y/3),
  114.                             Point( x/2+x/5, y-y/4 ) ) );
  115. }
  116.  
  117. // --- PaintWindow::Resize() ---------------------------------------
  118.  
  119. void PaintWindow::Resize()
  120. {
  121.     x = GetOutputSizePixel().Width();
  122.     y = GetOutputSizePixel().Height();
  123.     if ( x > y )
  124.         a = y;
  125.     else
  126.         a = x;
  127.  
  128.     if ( bMapModeChanged )
  129.     {
  130.         MapMode aMode = GetMapMode();
  131.         aMode.ChangeOrigin( Point( x*-1, y*-1 ) );
  132.         ChangeMapMode( aMode );
  133.     }
  134.  
  135.     Invalidate();
  136. }
  137.  
  138. // --- PaintWindow::MouseButtonDown() ------------------------------
  139.  
  140. void PaintWindow::MouseButtonDown( const MouseEvent& )
  141. {
  142.     MapMode aMapMode( MAP_PIXEL,
  143.                       Point( GetOutputSizePixel().Width()*-1,
  144.                              GetOutputSizePixel().Height()*-1 ),
  145.                       Fraction( -1, 1 ), Fraction( -1, 1 ) );
  146.  
  147.     if ( bMapModeChanged )
  148.         ChangeMapMode( MapMode() );
  149.     else
  150.         ChangeMapMode( aMapMode );
  151.     bMapModeChanged = !bMapModeChanged;
  152.  
  153.     Invalidate();
  154. }
  155.  
  156.  
  157. // --- PaintWindow::PacMan() ---------------------------------------
  158.  
  159. void PaintWindow::PacMan( AutoTimer* )
  160. {
  161.     if ( ( bOpen ) && ( t < a/10 ) )
  162.         t++;
  163.     else if ( ( bOpen ) && ( t >= a/10 ) )
  164.         bOpen = FALSE;
  165.     if ( ( !bOpen ) && ( t > 1 ) )
  166.         t--;
  167.     else if ( ( !bOpen ) && ( t <= 1 ) )
  168.         bOpen = TRUE;
  169.  
  170.     ChangePen( Pen( Color( COL_WHITE ), 0 ) );
  171.     ChangeFillInBrush( Brush( Color( COL_WHITE ) ) );
  172.     DrawPie( Rectangle( Point( x/2-a/12, y/2-a/12 ),
  173.                         Size( a/6, a/6 ) ),
  174.                         Point( x/2+a/12, y/2+t ),
  175.                         Point( x/2+a/12, y/2-t ) );
  176.  
  177.     ChangeFillInBrush( Brush( Color( COL_YELLOW ) ) );
  178.     DrawPie( Rectangle( Point( x/2-a/12, y/2-a/12 ),
  179.                         Size( a/6, a/6 ) ),
  180.                         Point( x/2+a/12, y/2-t ),
  181.                         Point( x/2+a/12, y/2+t ) );
  182.  
  183.     ChangePen( Pen( Color( COL_BLACK ), 0 ) );
  184.     ChangeFillInBrush( Brush( Color( COL_BLACK ) ) );
  185.     DrawEllipse( Rectangle( Point( x/2+a/48, y/2-a/16 ),
  186.                             Size( 5, 5 ) ) );
  187. }
  188.  
  189. // --- MyApp::Main() -----------------------------------------------
  190.  
  191. void MyApp::Main( int, char*[] )
  192. {
  193.    PaintWindow aWindow;
  194.    Execute();
  195. }
  196.  
  197. // --- aMyApp ------------------------------------------------------
  198.  
  199. MyApp aMyApp;
  200.  
  201. #ifdef MAC
  202.     Application* pApp = &aMyApp;
  203. #endif
  204.